package ui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

import org.jdesktop.swingx.SwingXUtilities;

public class ZoomInfoWindow extends JDialog {
	private static final long serialVersionUID = 1L;
	private Image image;
	private ImagePanel imagepanel;
	private ImageEditor editor;

	public ZoomInfoWindow(Image image2) {
		this(image2, null);
	}

	public ZoomInfoWindow(Image zoomImage, ImageEditor editor) {
		super(editor,false);
		this.editor = editor;
		
		setTitle("Gespeichertes Bild anzeigen");
		Component source = null;
		JPanel outerImagePanel = new JPanel();
		JPanel panel = new JPanel();
		outerImagePanel.setLayout(new BoxLayout(outerImagePanel,
				BoxLayout.PAGE_AXIS));
		panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
		image = zoomImage;
		imagepanel = new ImagePanel(image);
		imagepanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3));
		JLabel label = new JLabel("Dieses Zoombild wurde gespeichert:");
		label.setFont(new Font("Dialog", Font.BOLD, 16));
		JButton fertig = new JButton(new ImageIcon(
				"./src/ui/images/button_ok.png"));
		fertig.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				exit();
			}
		});
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent _) {
				exit();
			}
		});
		this.setIconImage(Toolkit.getDefaultToolkit().createImage(
				"./src/ui/images/applications_graphics.png"));
		outerImagePanel.add(new AlignBox(label));
		outerImagePanel.add(new JLabel(" "));
		outerImagePanel.add(imagepanel);
		panel.add(outerImagePanel);
		panel.add(new StretchBox(fertig));
		fertig.setPreferredSize(new Dimension(80, 80));
		this.add(panel);
		Border border1 = BorderFactory.createEmptyBorder(20, 30, 40, 30);
		outerImagePanel.setBorder(border1);

		pack();
		setLocationRelativeTo(source);
		fertig.setFocusPainted(false);
		setVisible(true);
	}

	protected void exit() {
		if (editor != null)
			editor.enableAllButtons(true);
		dispose();
	}

}
